<h2 class="ico_page">Send NewsLetter</h2>
<fieldset>
    <legend>Set Up Batch</legend>
    <table id="table" >
        <tr>
            <td width="14%">
                Recipients Group:
            </td>
            <td align="left" width="15%">
                <select class="long" id="select_group">
                    <option>Registered User</option>
                </select>
            </td>
        </tr>
        <tr>
            <td >
                Select Letter:
            </td>
            <td align="left" width="15%">
                <select class="long" id="select_letter">
                    <option></option>
                    {{if isset($letters)}}
                    {{foreach from=$letters item=l}}
                    <option value="{{$l->id}}" >{{$l->name}}</option>
                    {{/foreach}}
                    {{/if}}
                </select>
            </td>
            <td align="left">
                <button onclick="send_letters();">Send Batch </button>
            </td>
        </tr>

    </table>
</fieldset>

<script type="text/javascript">
    function send_letters(){
        letter =    $("#select_letter").val();
        group  = $("#select_group").val();

        if(letter.length && group.length){
            
            $.ajax({
                type:"POST",
                dataType:'text',
                data:"is_ajax=1&group_id="+group+"&letter_id="+letter,
                url: module_admin_url+"/send_letters/send",
                beforeSend: function(){
                     $.blockUI( {message: "<h1>Batch emailing..please wait..</h1>"});
                },
                complete :  function(data){
                    $.unblockUI();
                    $.blockUI( {message: "<h1>Done!!</h1>"});
                    $.unblockUI();
                }
            });
           
        }else{
            alert("Select valid GROUP and LETTER!");
        }
    }
</script>